LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-16-2010, 05:42 PM   #1
El Mago
LQ Newbie
 
Registered: Mar 2004
Posts: 26

Rep: Reputation: 15
Can't upload images with HTML forms


Well, the title says it all. I have a form like this in my document:


<form enctype="multipart/form-data" name="profile" method="post" action="?">

<input type="hidden" name="MAX_FILE_SIZE" value="250000">
Select image:<input type="file" name="image" />
<br />

<p class="centered">
<input value="Confirm" type="submit" class="button1 linkElement" />
</p>
</form>


The php code, that should handle the upload is standard:
move_uploaded_file($_FILES["image"]["tmp_name"], $destination);

I even printed the $_FILES array and it looks like this:
Array ( [image] => Array ( [name] => bojan.jpg [type] => image/jpeg [tmp_name] => /var/upload/phpjarPwZ [error] => 0 [size] => 10096 ) )

But the problem is that this file never gets saved to /var/upload directory (I changed php.ini file, so that uploaded files should be saved into /var/upload. I tried /var/tmp as well, but it's the same). Here are also the permissions of this dir:
drwxr-xr-x 2 apache apache 48 2010-02-17 00:30 upload

BTW, I use Mandriva 2010 64 bit distribution.
I spent last two days searching for solution on internet forums, asking people and made absolutely no progress.

Any ideas?

Oh, and is it possible to debug what is happening with the supposedly uploaded file? I mean any logs, where I could find trace, what's going wrong? I tried to check /var/log/httpd and files in there, but no success either...

 
Old 02-16-2010, 08:09 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
Can you do something like this
Code:
echo "tmp_name is '" . $_FILES["image"]["tmp_name"] . "'\n";
echo "destination is '" . $destination . "'\n";
Note the "'"s, to mark the start and end of the variables. Are these what they should be?

If they are what they should be, then post your complete HTML file and complete PHP file. Or at least a minimized version of the HTML/PHP files, such that it can still reproduce the problem.

Quote:
Here are also the permissions of this dir:
Code:
drwxr-xr-x 2 apache apache 48 2010-02-17 00:30 upload
Depending on your setup, "o"thers must have "w"rite permissions--here they'yre only given read and execute.
 
Old 02-16-2010, 08:53 PM   #3
MC10
LQ Newbie
 
Registered: Feb 2010
Posts: 5

Rep: Reputation: 0
This may be of some use to you. Maybe it doesn't work because you use "move_uploaded_file" rather than "@move_uploaded_file"?
 
Old 02-17-2010, 07:47 AM   #4
El Mago
LQ Newbie
 
Registered: Mar 2004
Posts: 26

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by nadroj View Post
Can you do something like this
Code:
echo "tmp_name is '" . $_FILES["image"]["tmp_name"] . "'\n";
echo "destination is '" . $destination . "'\n";
Note the "'"s, to mark the start and end of the variables. Are these what they should be?

If they are what they should be, then post your complete HTML file and complete PHP file. Or at least a minimized version of the HTML/PHP files, such that it can still reproduce the problem.
$_FILES array looks perfectly OK. HTML code of the form looks just like the one I posted and PHP code is basically irrelevant, because the file doesn't get save into /var/upload. This is my main problem.


Quote:
Originally Posted by nadroj View Post
Depending on your setup, "o"thers must have "w"rite permissions--here they'yre only given read and execute.
Changed that with chmod a+w upload, but the situation is the same, "uploaded" file doesn't get saved in /var/upload.
 
Old 02-17-2010, 08:03 AM   #5
El Mago
LQ Newbie
 
Registered: Mar 2004
Posts: 26

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by MC10 View Post
This may be of some use to you. Maybe it doesn't work because you use "move_uploaded_file" rather than "@move_uploaded_file"?
As I said before, move_uploaded_file can't fail in this case, because there is nothing to move in the first place. The file doesn't get saved into temporary location, this is my main issue.

Does anyone know, in which logs I could see any possible error messages?
 
Old 02-17-2010, 09:46 PM   #6
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
I dont know what logs if any it would be in. As I said before, I think I can further help only if you post all of your code (html, php, etc) for me or others to try and see if it works on our side, or if we can debug it ourselves.
 
Old 02-18-2010, 03:43 AM   #7
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

Are you positive $destination is correct? And does the apache user have write access to it? PHP will delete all uploaded files when the script ends unless you move or copy the files. So if it can't move the file, it will simply vanish. And if warnings are turned off, you will never know. Turn on displaying of all warnings/notices. Then try to check the contents of /var/upload in the script handling the upload. For example:

error_reporting(E_ALL);
passthru("ls -l /var/upload");
move_uploaded_file($_FILES["image"]["tmp_name"], $destination);
 
Old 02-18-2010, 08:09 AM   #8
El Mago
LQ Newbie
 
Registered: Mar 2004
Posts: 26

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Guttorm View Post
Hi

Are you positive $destination is correct? And does the apache user have write access to it? PHP will delete all uploaded files when the script ends unless you move or copy the files. So if it can't move the file, it will simply vanish. And if warnings are turned off, you will never know. Turn on displaying of all warnings/notices. Then try to check the contents of /var/upload in the script handling the upload. For example:

error_reporting(E_ALL);
passthru("ls -l /var/upload");
move_uploaded_file($_FILES["image"]["tmp_name"], $destination);
That was the key information I needed. When I included your code into my php script, I could finally reveal the error in my php code. Which I could not find before, as I assumed that the uploaded file will be left in /var/upload if it is not moved.
Thank you and all the others that tried to help me very much.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML Forms and fieldset shmuck Programming 1 02-27-2008 10:30 PM
LXer: Html Forms and PHP LXer Syndicated Linux News 0 01-09-2007 01:33 AM
Forms in HTML J_K9 Programming 5 06-30-2005 02:21 PM
HTML Forms belorion Programming 1 02-01-2005 11:41 PM
Breaking up html forms logicdisaster Programming 4 06-18-2004 12:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration