Community discussion forum
Uploading files in PHP
-
This thread is for discussions of Uploading files in PHP.
-
Advertisement
Simply the fastest line-level profiler for .NET ever
“The low overhead means it has minimal impact on the execution of my program”
Mark Everest, Development Team Leader, Renault F1 Team Ltd.Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now
-
when a partner wrote a simple script to receive uploaded files, the owner of the file was set to nobody, which is the apache webserver, I believe.
In this case, we can't access or manipulate the uploaded files via ftp or the shell. Chmod doesn't seem to work.
Are we doing something wrong or is this always the case?
Thanks,
Collin -
Hi,
I'm a new inexpert php programmer.
I've tested your script upload.html and upload.php and it is all ok.
Now, I like modify script to upload a specified file (i.e c:\pippo.ttt) from pc to server, without insert manually the file name in the input box, but I have some problems.
test 1)
I try to substitute in upload.htm the line:
:---------
submit this file: <input type=file name="userfile"><br>
:---------
with this line :
:---------
submit this file: <input type="hidden" name="userfile" value="c
ippo.ttt"><br>
:---------
... but the server ( http://infrarossi.free.fr/test/upload5.htm ) replay :
:---------
Warning: Unable to open 'c
ippo.ttt' for reading: No such file or directory in your script on line 12
:---------
test 2)
to debug I add a line in upload.php
:---------
echo "$userfile";
echo "<br>-xxx-<br>";
:---------
... but the server replay:
:---------
./phpIV1Asq
-xxx-
Warning: Unable to open 'c
ippo.ttt' for reading: No such file or directory in your script on line 9
:---------
The question:
Why the string c
ippo.ttt is echoed as ./phpIV1As ?
Thank you for your help.
Best regards -
Hi,
I'm a new inexpert php programmer.
I've tested your script upload.html and upload.php and it is all ok.
Now, I like modify script to upload a specified file (i.e c:\pippo.ttt) from pc to server, without insert manually the file name in the input box, but I have some problems.
test 1)
I try to substitute in upload.htm the line:
:---------
submit this file: <input type=file name="userfile"><br>
:---------
with this line :
:---------
submit this file: <input type="hidden" name="userfile" value="c:pippo.ttt"><br>
:---------
... but the server ( http://infrarossi.free.fr/test/upload5.htm ) replay :
:---------
Warning: Unable to open 'c:pippo.ttt' for reading: No such file or directory in your script on line 12
:---------
test 2)
to debug I add a line in upload.php
:---------
echo "$userfile";
echo "<br>-xxx-<br>";
:---------
... but the server replay:
:---------
./phpIV1Asq
-xxx-
Warning: Unable to open 'c:pippo.ttt' for reading: No such file or directory in your script on line 9
:---------
The question:
Why the string c:pippo.ttt is echoed as ./phpIV1As ?
Thank you for your help.
Best regards -
I am new php programmer but when I test your upload php. I got a message
Warning: Unable to create '/home/www/phptest/test.txt': Permission denied in /home/www/phptest/upload.php on line 6
file uploaded
instead. what should I do to solve this prob? -
Try on a php supported server (i.e. sign up on www.free.fr)
bye -
Hi
Run your application from the "public" folder under your server's root directory.
S.S -
are you talking to me?
-
Hi!
I used this code for my upload form and worked ok...there's just something i can't get to work.
I placed a check for the "empty input field" and I can't get it to work.
<html>
<?
if(!empty($userfile)) {
copy($userfile, "kuva.gif");
echo("file uploaded");
}
else {
echo("FAILED!");
}
?>
</html>
No matter if I turn the code "upside down", it only does the "if" part..can you help me?
-meissi- -
That's so easy in my self server, but I am using free hosting like iwebland.com.
May I change temporary directory? no I think so.
I tried do a copy inside my root, and I discover that I haven't permision to do that.
I don't know java.
I can't use ftp because I can't give the access to my customer, but he need put images in the database.
May redirect the upload trought "<input type=file..." to the directory in my root? -
I have a little prob
I am new php programmer but when I test your upload php. I got a message
Warning: Unable to create '/home/www/phptest/test.txt': Permission denied in /home/www/phptest/upload.php on line 6
file up...
You need to make sure the directory you are uploading to has write permissions. If it doesn't you will get that error! -
I have had this problem before. Your code appears to be ok so it seems odd that it is not working. Try using the same code but without the braces {} - this often helps me in PHP when for some reason the second branch of the conditional is never reached.
Quote: [1]Posted by meissi on 26 Feb 2003 06:32 AM[/1]
Hi!
I used this code for my upload form and worked ok...there's just something i can't get to work.
I placed a check for the "empty input field" and I can't get it to work.
<html>
<?
if(!empty($userfile)) {
copy($userfile, "kuva.gif");
echo("file uploaded");
}
else {
echo("FAILED!");
}
?>
</html>
No matter if I turn the code "upside down", it only does the "if" part..can you help me?
-meissi-
-
Quote: ...I am new php programmer but when I test your upload php. I got a message
Warning: Unable to create '/home/www/phptest/test.txt': Permission denied in /home/www/phptest/upl
bonk on head
Perhaps you don't have a www/phptest/ folder
The text "'/home/www/phptest/test.txt" was just an example, you can make it anything you want, as long as its a valid place in your webspace. -
"./phpIV1As" sounds like a directory name, probably the directory of your php folder or where your files are stored on your webspace, which may be inaccessable to you.
With your "c:pippo.ttt" file name, have you tried putting in the "\" backspace after C: in this text? If you don't, which is what you have done here, then PHP will look for the pippo.ttt file in the present working directory of the C: Drive, which is unnecessarily the root folder of the C: drive. -
Perhaps it's more likely that the data getting put into $userfile is not working properly leaving it empty.
I'd also rather have "<?php" instead of just "<?" when starting to write php code.
<?php
if(!empty($userfile))
{
copy($userfile, "kuva.gif");
echo("file uploaded");
}
else
{
echo("FAILED!");
}
?> -
Some more posts on this topic (comments page took me to forums
):
-
Hello, I have tried using your script and I have checked over my code for syntax and it appears to be the exact same as yours. When I test it, it appears to not upload anything and skips right to the else statement "FAILED". It appears as username is not being passed properly to the php page. Also copy($userfile, "kuva.gif"); that line what should the value in " " be. THe path where the uploaded file is going to be stored? I dont understand how someone could have a .gif. Plz help
HTML PAGE
<html>
<form action="myupload.php" method=post enctype="multipart/form-data">
submit this file: <input type=file name="userfile"><br>
<input type=submit>
<br>
</form>
</html>
PHP
<html>
<?php
if(!empty($userfile)) {
copy($userfile, "kuva.gif");
echo("file uploaded");
}
else {
echo("FAILED!");
}
?>
</html> -
This is due to a change in the way PHP lets you access POST'ed variables. I've updated the article to reflect these changes.
-
Sorry about the delayed reply! Try this:
<?php
if(!empty($userfile))
{
copy($userfile, "kuva.gif");
echo("file uploaded");
}
elseif (empty($userfile))
{
echo("FAILED!");
}
?> -
i
when execute that script the value of $FILES["userfile"]["tmpname"], $FILES["userfile"]["type"], and $FILES["userfile"]["size"] are empty,
the value of $_FILES["userfile"]["name"], yes, take the name of the file to upload, but, don't make nothing, why ?
thank's in advance -
I seem to have the same problem as someone in an earlier post. I don't seem to have my directory correct. Here is the portion of my code that specifies the directory:
moveuploadedfile($FILES['userfile']['tmpname'], "home/successa/publichtml/".$FILES['userfile']['name']);
When I run it, I get:
Warning: moveuploadedfile(home/successa/publichtml/NTUSER.DAT.LOG): failed to open stream: No such file or directory in /home/successa/publichtml/processfile.php on line 15
Warning: moveuploadedfile(): Unable to move '/tmp/php6fQXnx' to 'home/successa/publichtml/NTUSER.DAT.LOG' in /home/successa/publichtml/processfile.php on line 15
I don't know how to specify the directory. When I log into my control panel, whatever root directory I am in, I see a publichtml folder there. I've tried just specifying "/publichtml" as the directory but that doesn't work either! I read someplace that it should be the "absolute location" but in this case I'm not sure what that means. I've checked for write permission and I do have that...??? I feel so dumb!
-
Hello, I am new to PHP and have done a little bit of research into uploading files. I believe you need to have a 'hidden' field in the form called 'MAXFILESIZE' with a value no greater than 2000000(that's the default in most PHP configs). I hope this helps!
Nick -
Try $FILES['userfile']["tmpname"] ... I even had to 'waste' the single quote in a script where the var userfile was variable itself.
Steven -
You might want to replace the double quotes in the second [] too ...
Steven -
This error message is common when the upload directory does not have the right permissions for the web server to write to it.
You must change the write permissions of the upload directory allowing the web server to write to it. -
Are there C functions equivalent to those in php which will allow
me to write the upload.php in C? I have a lot of form processing
that is all written in C, and I would like to integrate the uploading
of files right into other procedures.
Thanks for you help.
John -
i have done everything you have said and this error comes up and cant figure out what this means right now
Parse error: parse error, unexpected T_IF in c:\appserv\www\upload.php on line 7
Thanks for any reply -
The problem is a missing ";"
add a semi colon after:
$uploaddir = "/upload/" -
The T_IF error is the missing ";" at the end of the $uploaddir = "/path" statement in his code. In my case the code simply isn't working and I'm not sure why. The file just doesn't upload.
-
You should add quotation marks to the upload.htm script as follows:
method=post change to method="post"
type=file change to type="file"
type=submit change to type="submit"
Also note - The php manual recommends you include max file size, which appearently warns the user before the upload begins.
btw the script worked fine for me after these corrections -
how can i get the exact address of the uploaded file i browsed.
like when i browsed it from "C:/picture.bmp"
how can i get this address? i mean how could i get these exact words?
and when i upload this picture to the server, i declared the address of the server.
but then it says, "permission denied"
what does it mean? -
Hi,
I'm relatively new to php. I'm using a code simliar to the one posted for file uploads. I was wondering if there was any way to set the permisson to "read only" upon upload. I've been having problems with uploading images that will only display if I manually set the permission in my site admin tool. Any help would be muck appreciated.
Thank you,
Mike -
gud day!
i have problems regarding the file i uploaded on the server.
the file is pic.bmp
i uploaded it in "subs/images"
then i am about to create an exec statement to convert this logo.
its permission is "-rw-------" and i would like to change it.
i typed "chmod 777 pic.bmp"
it says "operation not permitted"
what can i do? -
Is there anyway to change the filename as it is uploaded? So myhouse.jpg is auto changed to file1.jpg
For instance, anytime a file is uploaded via the form... Have it name the file MYFILE.jpg
so that when a new file is uploaded it overwrites the old file without having to have the user specify the correct filename before uploading it. -
I am trying to allow people to upload image files and post them to me.
I have copied your code exactly but get the following;
Parse error: parse error, unexpected T_IF in /nfs1/expatriatespain.com/www/test site/myupload.php on line 16
Any ideas?
Post a reply
Related discussion
-
Beginning from scratch
by Slicksim (1 replies)
-
How to modularize CSS menus
by Slicksim (2 replies)
-
What technology / Framework would you propose
by James Crowley (2 replies)
-
ASP VS PHP
by paulfp (9 replies)
-
What would motivate you to change your job?
by kovshenin (4 replies)
Related articles
Quick links
Recent activity
- jack semwal replied to i have struck with my proj...
- Mandy Bradley replied to Help please for student
- Barry Roberts replied to Loop help needed
- Navin Hirani replied to Error in VB code
- Marissa Levy replied to Gizmox Announces release of...
- manjunath L replied to Regarding Visual Basic Programme
Enter your message below
Sign in or Join us (it's free).