Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

upload error

images php coding issues or problems here.

Moderators: macek, egami, gesf

upload error

Postby begeiste » Mon Aug 29, 2005 11:02 am

I have created a folder call 'uploads' inside of add_record folder:www/charlton/icccon/add_record/uploads directory, would like to upload a thum_anne.jpg from images folder where is www/charlton/icccon/member/images diretory, but it failed and found the warning sentence below, I don't have much hairs before this problem, and has a quite few less now, can you please help me to solve this problem?

Warning: move_uploaded_file(/www/charlton/icccon/add_record/uploads/thum_anne.jpg): failed to open stream: No such file or directory in c:\program files\easyphp1-8\www\charlton\icccon\add_record\processing_upload.php on line 17



Code: Select all
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="processing_upload.php" 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 type="submit" value="Send File" /> </form>>


Code: Select all
<body>
 <?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/www/charlton/icccon/add_record/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
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>";

?>
</body>
begeiste
New php-forum User
New php-forum User
 
Posts: 83
Joined: Thu Jun 03, 2004 11:27 am

Postby karnetics » Tue Aug 30, 2005 9:41 am

try this...

Say your upload.php script is located under your root directy which is /www/myimages/
and you upload load for is located under /www/myimages/uploads/

Try using for example

$uploaddir = 'uploads/';

or if your upload.php script is located under /www/myimages/includes then the path would be

$uploaddir = '/uploads/';

reason.

if you set $uploaddir = /www/myimages/uploads/ and my upload.php script is in the myimages folder.. Then when trying to use the move_uploaded_file(), this is what happens when the script is run.. The function will see the path as /www/myimages/uploads/www/myimages/upload... This is confusing to the function so it gives you a big fat error messege.

but if you set $uploaddir = 'uploads/' and run the script.. The move_upload_file() will find the path.

but try that and see if it works..
karnetics
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Aug 30, 2005 8:57 am

Postby WiZARD » Tue Aug 30, 2005 10:27 am

try to determinate current path: realpath(dirname(__FILE__))
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Postby begeiste » Tue Aug 30, 2005 2:04 pm

karnetics wrote:try this...

Say your upload.php script is located under your root directy which is /www/myimages/
and you upload load for is located under /www/myimages/uploads/

Try using for example

$uploaddir = 'uploads/';

or if your upload.php script is located under /www/myimages/includes then the path would be

$uploaddir = '/uploads/';

reason.

if you set $uploaddir = /www/myimages/uploads/ and my upload.php script is in the myimages folder.. Then when trying to use the move_uploaded_file(), this is what happens when the script is run.. The function will see the path as /www/myimages/uploads/www/myimages/upload... This is confusing to the function so it gives you a big fat error messege.

but if you set $uploaddir = 'uploads/' and run the script.. The move_upload_file() will find the path.

but try that and see if it works..


Thanks for your suggestion. I created a folder call 'myimages' inside of www folder and having upload.php and process_upload.php pages inside of myimages folder. Also having uploads folder inside of myimages folder. They are now:
www/myimages/upload.php and www/myimages/uploads, but I still got a fat error message:
Warning: move_uploaded_file(/uploads/thum_anne.jpg): failed to open stream: No such file or directory in c:\program files\easyphp1-8\www\myimages\processing_upload.php on line 17



Warning: move_uploaded_file(): Unable to move 'C:/Program Files/EasyPHP1-8\tmp\php187.tmp' to '/uploads/thum_anne.jpg' in c:\program files\easyphp1-8\www\myimages\processing_upload.php on line 17

Possible file upload attack!
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => thum_anne.jpg
[type] => image/jpeg
[tmp_name] => C:/Program Files/EasyPHP1-8\tmp\php187.tmp
[error] => 0
[size] => 11984
)

)

I am not sure where I messed them up?



Code: Select all
<body>
 <?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

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

echo '<pre>';
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>";

?>
begeiste
New php-forum User
New php-forum User
 
Posts: 83
Joined: Thu Jun 03, 2004 11:27 am

Postby karnetics » Wed Aug 31, 2005 7:46 am

Your error is with your path.. If you have the script files inside the image folder then your path would be
$uploaddir = ' . '; //meaning current folder.

If you move your form & script file outsite the upload directory.. The path should be $uploaddir = 'upload/'; //meaning copy into the folder uploads...

And say if you created a folder called includes.. and move your form & script file into the folder include.
Then you would have to name your path $uploaddir = '/uploads/';

Also note if you use one of the following methods.. If you would like to view the image the same method applys...
example

if my image is set the the path $uploaddir. Depending on where your result script is located you will have to set the path the same or add a slash before the path..

Viewimage.php is located under my root.
The source of my image would be <img src='upload/imagename'>


Here is what I did...

my folder and file structure

/www/
|
|
--->(folder) myimages
| ---->(form) upload.php
|-----(script file) process_upload.php
|
----> (folder) uploads/
------------------------------------------------------------------
# <body>
# <?php
# // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
# // of $_FILES.
#
# $uploaddir = 'uploads/'; //since my script is out side the upload folder. The path should be this $uploaddir = 'uploads/'.

# $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
#
# echo '<pre>';
# 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>";
#
# ?>
karnetics
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Aug 30, 2005 8:57 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.