[PHP] Error with : move_uploaded_file

Hi All !

I've a bug with my upload page in php.

It's work fine on a Linux Server, but with my mac on Local it doesn't work.

I use :

$tempFile = $ FILES['Filedata']['tmpname'];
$targetPath = $ SERVER['DOCUMENTROOT'] . $_GET['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
if(is uploadedfile($tempFile)){
if(move uploadedfile($tempFile,$targetFile)){
echo 1;
}else{
echo 0;
}
}

________________________________________________________________________________ __

This is the error returned :

Warning: move uploaded_file(/Library/WebServer/Documents/~KicheTof/Gallerie/admin/upload/img/i mgtemp/tof.jpg) [ function.move-uploaded-file]: failed to open stream: No such file or directory in /Users/KicheTof/Sites/Gallerie/admin/upload/upload.php on line 11



Warning: move uploadedfile() [ function.move-uploaded-file]: Unable to move '/private/var/tmp/php/php3q2s1h' to '/Library/WebServer/Documents/~KicheTof/Gallerie/admin/upload/img/img_temp/tof. jpg' in /Users/KicheTof/Sites/Gallerie/admin/upload/upload.php on line 11



I tried to set the uploadtmpdir in php.ini but it doesn't change anything

________________________________________________________________________________ __

The CHMOD of the folders :

drwxrwxrwx+ 15 KicheTof staff 510 14 jul 22:17 Sites
drwxrwxrwx 13 KicheTof staff 442 14 jul 18:07 Gallerie
drwxrwxrwx 13 KicheTof staff 442 16 jul 18:13 admin
drwxrwxrwx 16 KicheTof staff 544 16 jul 19:07 upload
drwxrwxrwx 6 KicheTof staff 204 16 jul 18:13 img
drwxrwxrwx 10 KicheTof staff 340 16 jul 18:13 img_temp

________________________________________________________________________________ __


I hope you have the solution! I searched for about 5 hours without success =(

Thank's !

Christophe

MacBook Pro Unibody, Mac OS X (10.5.7), PHP Version 5.2.8

Posted on Jul 16, 2009 11:12 AM

Reply
7 replies

Jul 16, 2009 7:33 PM in response to KicheTof

More than likely the problem is that the permissions on the directories are wrong. All directories for any website should be owned by the '_www' user which is 'who' the apache process runs as. Try changing them like this:

sudo chown -R _www:admin /Library/Webserver/<documentroot>/*

where <documentroot> is the name of the directory where the website files and directories are.

Jul 18, 2009 1:03 AM in response to jaydisc

Hello !

I've a bug..

KicheTof$ ls -al /Library/WebServer/Documents/~KicheTof/Gallerie/admin/upload/img/img_temp
ls: /Library/WebServer/Documents/~KicheTof/Gallerie/admin/upload/img/img_temp: No such file or directory



<?php
if (!empty($_FILES) && $_FILES['Filedata']['error'] == 0) {
$tempFile = $FILES['Filedata']['tmpname'];
$targetPath = $SERVER['DOCUMENTROOT'] . $_GET['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
if(isuploadedfile($tempFile)){
if(moveuploadedfile($tempFile,$targetFile)){
chmod($targetFile,0666);
echo 1;
}else{
echo 0;
}
}
}else{
echo "error fichier : ".$_FILES['Filedata']['error'];
}
?>



sudo chown -R _www:admin /Library/Webserver/<documentroot>/*


-->
KicheTof$ sudo chown -R _www:admin /Library/WebServer/Documents/~Kichetof/*
chown: /Library/WebServer/Documents/~Kichetof/*: No such file or directory


I've change the permissions in my folder : /Users/KicheTof/Sites
KicheTof$ sudo chown -R _www:admin /Users/KicheTof/Sites/~Kichetof/*


But it's doesn't work 😟

Jul 18, 2009 2:11 AM in response to KicheTof

I think it's the location of files.

My site is located in /Users/KicheTof/Sites and the folder where my page is trying to place is /Library/WebServer/Documents/~KicheTof/Gallerie/admin/upload/img/img_temp/, but this folder doesn't exist here. It's in /users/KicheTof/Site/Gallerie..


So I think the apache configuration to a problem.

This my httpd-userdir.conf that include in httpd.conf

UserDir Sites
Include /private/etc/apache2/users/*.conf


This my KicheTof.conf in users/

<Directory "/Users/KicheTof/Sites/">
Options Indexes MultiViews Includes FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>

Jul 18, 2009 4:49 PM in response to KicheTof

The problem is that the paths you are passing for the future location of the file either don't exist or don't have the correct privileges.

Your $targetPath is wrong. You are using:

$SERVER['DOCUMENTROOT']


Which is set to /Library/WebServer/Documents. However, it sounds like that's not really the root of where you've put your site's files. So,

1. Put your site there, or
2. Change the settings for the Site in ServerAdmin to point to a different site root, or
3. Stop using DOCUMENT_ROOT as part of the path of where to put the file.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

[PHP] Error with : move_uploaded_file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.