| | |
Issue with uploading files
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 149
Reputation:
Solved Threads: 25
The problem you're having is $_FILES['userfile']['tmp_name'] is an actual filename. your destination is a directory without a file name. its trying to create a file named "uploads", which is a valid filename on a linux system, in your dw folder. Try actually giving the file a filename in the destination path.
Example:
Source: php.net (move_uploaded_file)
Notice how in that code the destination is /uploads/[name of the actual file]. Should solve your problem.
Example:
php Syntax (Toggle Plain Text)
<?php $uploads_dir = '/uploads'; foreach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; move_uploaded_file($tmp_name, "$uploads_dir/$name"); } } ?>
Notice how in that code the destination is /uploads/[name of the actual file]. Should solve your problem.
If you're question/problem is solved don't forget to mark the thread as Solved!
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.12 or 5.3.1
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.12 or 5.3.1
•
•
•
•
The problem you're having is $_FILES['userfile']['tmp_name'] is an actual filename. your destination is a directory without a file name. its trying to create a file named "uploads", which is a valid filename on a linux system, in your dw folder. Try actually giving the file a filename in the destination path.
Example:
Source: php.net (move_uploaded_file)php Syntax (Toggle Plain Text)
<?php $uploads_dir = '/uploads'; foreach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; move_uploaded_file($tmp_name, "$uploads_dir/$name"); } } ?>
Notice how in that code the destination is /uploads/[name of the actual file]. Should solve your problem.
i tried modifiying the code to suit my form code and still got the same error
php Syntax (Toggle Plain Text)
<?php $uploads_dir = "uploads/"; foreach($_FILES['userfile']['error'] as $key => $error) { if($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES['userfile']['tmp_name'][$key]; $name = $_FILES['userfile']['name'][$key]; move_uploaded_file($tmp_name, $uploads_dir .$name); } } ?>
The error i got is:
Warning: Invalid argument supplied for foreach() in /home/alanhuno/public_html/upload2.php on line 4
@ I'm gonna live forever, or die trying.
@ A wise man once told me, in order to understand recursion, you first must understand recursion.
@ A wise man once told me, in order to understand recursion, you first must understand recursion.
•
•
•
•
I tried the above code but it gives an error on the foreach line saying that it is an invalid argument?
i tried modifiying the code to suit my form code and still got the same error
php Syntax (Toggle Plain Text)
<?php $uploads_dir = "uploads/"; foreach($_FILES['userfile']['error'] as $key => $error) { if($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES['userfile']['tmp_name'][$key]; $name = $_FILES['userfile']['name'][$key]; move_uploaded_file($tmp_name, $uploads_dir .$name); } } ?>
The error i got is:
Warning: Invalid argument supplied for foreach() in /home/alanhuno/public_html/upload2.php on line 4
php Syntax (Toggle Plain Text)
<?php $uploads_dir = "uploads/"; $tmp_name = $_FILES['userfile']['tmp_name']; $name = $_FILES['userfile']['name']; move_uploaded_file($tmp_name, $uploads_dir .$name) or die("could not upload file"); ?>
Thanks to all who tried to help. I hope my hair grows back now
@ I'm gonna live forever, or die trying.
@ A wise man once told me, in order to understand recursion, you first must understand recursion.
@ A wise man once told me, in order to understand recursion, you first must understand recursion.
•
•
Join Date: Apr 2009
Posts: 5
Reputation:
Solved Threads: 1
•
•
•
•
Hi,
I am trying to write an upload script and everytime i try and upload a file it will give me an error.
Warning: move_uploaded_file(/home/******/public_html/dw/uploads) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/******/public_html/dw/upload2.php on line 3
I have checked that the folder is there as the error suggests that it is not there but it is definately there.
My code is as follows
upload1.php
html Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form enctype="multipart/form-data" method="post" action="upload2.php"> Send this file: <input name="userfile" type="file" /><br /> <input type="submit" value="Send File" /> </form> </body> </html>
and upload2.php
php Syntax (Toggle Plain Text)
<?php if (move_uploaded_file($_FILES['userfile']['tmp_name'], "/home/alanhuno/public_html/dw/uploads")) { print "Received {$_FILES['userfile']['name']} - its size is {$_FILES['userfile']['size']}"; } else { print "Upload Failed"; } ?>
are u working with xamp or wamp ?
this is only the path problem rest of the code is ok.
•
•
Join Date: Jul 2008
Posts: 149
Reputation:
Solved Threads: 25
That is what I was trying to illustrate as well, that it was a path problem, aka the filename was missing from the path, the code itself was fine. The example i posted was from the manual illustrating path + filename. I apologize for any confusion caused to the op.
If you're question/problem is solved don't forget to mark the thread as Solved!
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.12 or 5.3.1
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.12 or 5.3.1
•
•
Join Date: Apr 2009
Posts: 5
Reputation:
Solved Threads: 1
$img_name=time().$_FILES['img']['name']; // allow to upload more than one file with same name
$temp_file=$_FILES['img']['tmp_name'];
$dest_path="Image/".$img_name;
if(move_uploaded_file($temp_file,$dest_path)){
echo "File is sucessfully uploaded at Image directory";
}else{
echo "Error in uploading file";
}•
•
•
•
You can use this code . This will store your file at image directory.
•
•
•
•
$img_name=time().$_FILES['img']['name']; // allow to upload more than one file with same name $temp_file=$_FILES['img']['tmp_name']; $dest_path="Image/".$img_name; if(move_uploaded_file($temp_file,$dest_path)){ echo "File is sucessfully uploaded at Image directory"; }else{ echo "Error in uploading file"; }
@ I'm gonna live forever, or die trying.
@ A wise man once told me, in order to understand recursion, you first must understand recursion.
@ A wise man once told me, in order to understand recursion, you first must understand recursion.
![]() |
Similar Threads
- sharing files between to linksys routers. (Networking Hardware Configuration)
- Uploading files to mysql (PHP)
- Uploading files Access Denied Error (ASP.NET)
- Problem in Uploading Files using Register Global on/off (PHP)
- Uploading files onto the Web Server (ASP)
- Deleting Uploaded Files? (PHP)
- not-a-virusadware (Viruses, Spyware and other Nasties)
- Uploading files using HTTP/X and CGI (Shell Scripting)
Other Threads in the PHP Forum
- Previous Thread: delete a row/entry form table in mysql using textbox form.
- Next Thread: Calls to mysqli properties/functions returning errors
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error fcc file files folder form forms function functions google howtowriteathesis href htaccess html image include insert integration ip java javascript joomla limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop open parse paypal pdf php problem provider query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table template tutorial update upload url validation validator variable video web xml youtube





