TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   copy(upload/100_0376.JPG) [function.copy]: failed to open (http://www.talkphp.com/absolute-beginners/4984-copy-upload-100_0376-jpg-function-copy-failed-open.html)

ilangostl 09-29-2009 10:38 PM

copy(upload/100_0376.JPG) [function.copy]: failed to open
 
Now this is a new problem. I am trying to upload files. (This PHP application is in the following location on my Mac OS system: ~/Sites/samplesite2

So I am trying to do an upload and this is the error I get:
Notice: Undefined index: ufile in /Users/S/Sites/samplesite2/filebrowser/multiple_upload_ac.php on line 6

Notice: Undefined index: ufile in /Users/S/Sites/samplesite2/filebrowser/multiple_upload_ac.php on line 7

Notice: Undefined index: ufile in /Users/S/Sites/samplesite2/filebrowser/multiple_upload_ac.php on line 8

Warning: copy(upload/100_0376.JPG) [function.copy]: failed to open stream: Permission denied in /Users/S/Sites/samplesite2/filebrowser/multiple_upload_ac.php on line 11

Observations: Is this something to do with file permissions?
I set 777 for filebrowser, Sites, the upload folder, etc.

Or does this whole application go into some other apache2 folder?
Thanks in advance

The file pointed to is below:


<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1];
$path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2];

//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);

//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>";
echo "<img src=\"$path1\" width=\"150\" height=\"150\">";
echo "<P>";

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>";
echo "<img src=\"$path2\" width=\"150\" height=\"150\">";
echo "<P>";

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>";
echo "<img src=\"$path3\" width=\"150\" height=\"150\">";
?>

ioan1k 09-30-2009 12:45 AM

Couple of things here
  1. $HTTP_POST_FILES has been deprecated since about 4.1 I believe you need to use instead $_FILES
  2. For uploaded files you want to use move_uploaded_file instead of copyand do a simple if statement using http://us2.php.net/getimagesize]getimagesize to validate that the uploaded file is an image
  3. You cannot process the form with three files being uploaded with the same name, each image you upload must have unique name so it would become $_FILES['ufile1], $_FILES['ufile2'] etc etc...
  4. You need to set write permissions to the folder you are uploading (777)

sketchMedia 09-30-2009 10:04 AM

And you need to use forum tags to wrap your code samples to stop the wall of text crit my eyes have just experienced.


Edit ... GRRRRRRRR damn forum striped out my tags (and I did try to convert the [ ] o html entities), anyway this thread should show what I meant.
http://www.talkphp.com/lounge/4563-p...e-talkphp.html

ilangostl 10-01-2009 03:02 PM

Thank you. I am implementing those changes.


All times are GMT. The time now is 07:20 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0