Jump to content
  • Advertisement
Sign in to follow this  
sathenzar

[web] PHP - uploading images from local to server.

This topic is 4829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone, I was wondering if anyone knew a way to copy over a picture from the local space to the server space thorugh a function. Thanks in advance, -sathenzar.

Share this post


Link to post
Share on other sites
Advertisement
I've seen that and amazingly enough I dont' really understand how to set it up, which is sad b/c I've been programming PHP for over a year now, I should be able to do somthing as simple as this. Could someone build me a quick example if it wouldn't be to much to ask? Thanks in advance.

Share this post


Link to post
Share on other sites
well I tried it myself and I got these errors:
/blogs/beach.jpg
Warning: move_uploaded_file(/blogs/beach.jpg): failed to open stream: No such file or directory in /home/demon/public_html/blogs/test.php on line 12

Warning: move_uploaded_file(): Unable to move '/tmp/phpy5dvzu' to '/blogs/beach.jpg' in /home/demon/public_html/blogs/test.php on line 12
Possible file upload attack!
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => beach.jpg
[type] => image/pjpeg
[tmp_name] => /tmp/phpy5dvzu
[error] => 0
[size] => 28111
)

)

my code is here:

<?php
if($send_file)
{
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/blogs/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
echo "$uploadfile";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form enctype="multipart/form-data" action="<?php echo $GLOBALS[ 'PHP_SELF' ]; ?>" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input name="send_file" type="submit" id="send_file" value="Send File" />
</form>
</body>
</html>



Does anyone know why this is happening? I'm using a hosting server does that matter? Thanks in advance.

Share this post


Link to post
Share on other sites
Try using copy() instead of move_uploaded_files(). Also set the destination file with this:

$uploadfile = realpath() . "/blogs/" . _FILES["userfile"]["name"] ;

Share this post


Link to post
Share on other sites
now I get:
Warning: Wrong parameter count for realpath() in /home/demon/public_html/blogs/test.php on line 8

/blogs/beach.jpg
Warning: copy(/blogs/beach.jpg): failed to open stream: No such file or directory in /home/demon/public_html/blogs/test.php on line 12

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!