473,503 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP 4.3.11: move_uploaded_file

I can validate that the file uploaded because is_uploaded_file()
returns true.
---------
if (is_uploaded_file($_FILES['test-img']['tmp_name'])) {
echo "File ". $_FILES['test-img']['name'] ." uploaded
successfully.<br />";
}
------------------------
When I try to move the file using move_uploaded_file it fails.
--------------
if (move_uploaded_file($_FILES['test-img']['tmp_name'],
$_SERVER['DOCUMENT_ROOT']. "/members/images/test-file.gif" )) {
echo "File is valid, and was successfully uploaded.<br />";
} else {
echo "File move failed!<br />";
}
--------------------------

I have checked the existence and permissions on
$_SERVER['DOCUMENT_ROOT']. "/members/images/"
and it appears ok.

What I need is some suggestions on how to debug this.
move_uploaded_file just returns a boolean, no idea of why it fails.

thanks
bill
Nov 25 '06 #1
5 3338
Try error_reporting(E_ALL) and ini_set('display_errors', true) if
necessary. May print some warnings. If that doesn't help, maybe check
the owner of the directory/file, see if you have enough space, or if
you have a quota on the destination directory...

bill wrote:
I can validate that the file uploaded because is_uploaded_file()
returns true.
---------
if (is_uploaded_file($_FILES['test-img']['tmp_name'])) {
echo "File ". $_FILES['test-img']['name'] ." uploaded
successfully.<br />";
}
------------------------
When I try to move the file using move_uploaded_file it fails.
--------------
if (move_uploaded_file($_FILES['test-img']['tmp_name'],
$_SERVER['DOCUMENT_ROOT']. "/members/images/test-file.gif" )) {
echo "File is valid, and was successfully uploaded.<br />";
} else {
echo "File move failed!<br />";
}
--------------------------

I have checked the existence and permissions on
$_SERVER['DOCUMENT_ROOT']. "/members/images/"
and it appears ok.

What I need is some suggestions on how to debug this.
move_uploaded_file just returns a boolean, no idea of why it fails.

thanks
bill
Nov 25 '06 #2
petersprc wrote:
Try error_reporting(E_ALL) and ini_set('display_errors', true) if
necessary. May print some warnings. If that doesn't help, maybe check
the owner of the directory/file, see if you have enough space, or if
you have a quota on the destination directory...
That helped:
I get the error: Notice: Uninitialized string offset: 0 in
/hsphere/local/home/techserv/iwbreeders.info/members/do-test-upload.php
on line 31

where line 31 is:
echo $_FILES['test-img']['tmp_name'];
which was copied from the move statement:
if (move_uploaded_file($_FILES['test-img']['tmp_name'],
$_SERVER['DOCUMENT_ROOT']. "/members/images/test-file.gif" ))
--rest of if/else statement omitted--

clearly if $_FILES['test-img']['tmp_name'] is uninitialized the
move statement won't work.
I get the same error lower down, which I am discussing in another
thread ($_FILE variable returning null.

I suspect that I am making the same error both places, but can't
figure out what.
>
bill wrote:
>I can validate that the file uploaded because is_uploaded_file()
returns true.
---------
if (is_uploaded_file($_FILES['test-img']['tmp_name'])) {
echo "File ". $_FILES['test-img']['name'] ." uploaded
successfully.<br />";
}
------------------------
When I try to move the file using move_uploaded_file it fails.
--------------
if (move_uploaded_file($_FILES['test-img']['tmp_name'],
$_SERVER['DOCUMENT_ROOT']. "/members/images/test-file.gif" )) {
echo "File is valid, and was successfully uploaded.<br />";
} else {
echo "File move failed!<br />";
}
--------------------------

I have checked the existence and permissions on
$_SERVER['DOCUMENT_ROOT']. "/members/images/"
and it appears ok.

What I need is some suggestions on how to debug this.
move_uploaded_file just returns a boolean, no idea of why it fails.

thanks
bill
Nov 25 '06 #3
petersprc wrote:
Try error_reporting(E_ALL) and ini_set('display_errors', true) if
necessary. May print some warnings. If that doesn't help, maybe check
the owner of the directory/file, see if you have enough space, or if
you have a quota on the destination directory...
Ok, I have it tracked down and it was the usual: "programmer error"
if ($_FILES['test-img'] = "") {
die ("no input file");
}

while testing to see if the $_FILES array exists, I was setting
it to null.

Thank you very much for the enhanced error reporting suggestions.

bill
>
bill wrote:
>I can validate that the file uploaded because is_uploaded_file()
returns true.
---------
if (is_uploaded_file($_FILES['test-img']['tmp_name'])) {
echo "File ". $_FILES['test-img']['name'] ." uploaded
successfully.<br />";
}
------------------------
When I try to move the file using move_uploaded_file it fails.
--------------
if (move_uploaded_file($_FILES['test-img']['tmp_name'],
$_SERVER['DOCUMENT_ROOT']. "/members/images/test-file.gif" )) {
echo "File is valid, and was successfully uploaded.<br />";
} else {
echo "File move failed!<br />";
}
--------------------------

I have checked the existence and permissions on
$_SERVER['DOCUMENT_ROOT']. "/members/images/"
and it appears ok.

What I need is some suggestions on how to debug this.
move_uploaded_file just returns a boolean, no idea of why it fails.

thanks
bill
Nov 25 '06 #4
bill wrote:
petersprc wrote:
>Try error_reporting(E_ALL) and ini_set('display_errors', true) if
necessary. May print some warnings. If that doesn't help, maybe check
the owner of the directory/file, see if you have enough space, or if
you have a quota on the destination directory...

Ok, I have it tracked down and it was the usual: "programmer error"
if ($_FILES['test-img'] = "") {
die ("no input file");
}

while testing to see if the $_FILES array exists, I was setting
it to null.
That is why you always should write an if-statement like this:

if (constante == $variable)

because if you write 'if (constante = $variable)' you get an compilation
error.

--
Jørn Dahl-Stamnes
http://www.dahl-stamnes.net/dahls/
Nov 26 '06 #5
Jørn Dahl-Stamnes wrote:
bill wrote:
>petersprc wrote:
>>Try error_reporting(E_ALL) and ini_set('display_errors', true) if
necessary. May print some warnings. If that doesn't help, maybe check
the owner of the directory/file, see if you have enough space, or if
you have a quota on the destination directory...
Ok, I have it tracked down and it was the usual: "programmer error"
if ($_FILES['test-img'] = "") {
die ("no input file");
}

while testing to see if the $_FILES array exists, I was setting
it to null.

That is why you always should write an if-statement like this:

if (constante == $variable)

because if you write 'if (constante = $variable)' you get an compilation
error.
Excellent suggestion !
THanks.

bill
Nov 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7564
by: neo002244 | last post by:
The move_uploaded_file() function is very quirky. I want to allow users to upload images to the Web site. Here is the code: if(!move_uploaded_file($_FILES, $imagefile)) { die("Could not move...
1
4972
by: Paul Lamonby | last post by:
Hi, I am using Mac os10.3.3, running Apache and PHP 4.3.6 I am just starting to use my local Sites folder to test php for my sites, but I cannot seem to get move_uploaded_file() or copy() to...
1
2996
by: Felix Natter | last post by:
hi, I would like to upload a file (via a form), then read that (temporary) file and write the contents into a database. The first problem is that open_basedir=/home/CUSTOMER so I can't just read...
1
10633
by: sa | last post by:
Trying to upload a file using win xp/iis/php. I've given full access to all accounts trying to get this to work? Yet I'm still getting read errors. Simplified the script below to the bare...
6
3337
by: Stijn Goris | last post by:
HI all, I have created a script that allows a user to upload a picture. I have an IIS server runing on my own pc but the actual site runs an Apache server. The upload script worked perfectly on...
2
16246
by: Brian | last post by:
Hi I am moving a site to a new server, I have been testing it and one of the pages uses move_uploaded_file, but I get a Permission denied. The directory I am moving it to is chomd of 755, if...
1
4214
by: comp.lang.php | last post by:
Consider my code: if ($this->isSuccessful && is_file($_FILES)) { // STEP 6: MOVE RESUME TO DIRECTORY $uuid = $this->sfug->getUUID(); if (!$uuid) $this->sfug->setUUID(); $uuid =...
7
2054
by: nicemotion | last post by:
Hi all, the following easy script correctly insert a record in the DB but is not moving the images (Logo and Foto) to the server /foto folder. can't understand why 'cause the script is easy...
3
7554
by: groupie | last post by:
Hi, The code below is working - it returns the 'Received' message, however I cannot find the uploaded file in the destination folder, or anywhere else (other than source directory). I'm running...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.