Sign in to follow this  
sathenzar

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

Recommended Posts

sathenzar    100
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
sathenzar    100
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
sathenzar    100
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
microdot    324
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
sathenzar    100
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this