Reputation: 4771
I have looked through about 5 or so questions that are like this and none have solved my issue. Here is the the one that most the most helpful but still did not solve it PHP move_uploaded_file yet another not working.
Here is the code in question along with the debug code at the top.
$tempPath = $_FILES[ 'file' ][ 'tmp_name' ];
error_reporting(E_ALL); ini_set('display_errors', 1);
$uploadPath = storage_path() . '/uploads/' . 'test' . '.csv';
$targetDir = storage_path() . '/uploads/';
$realTargetDir = realpath($targetDir);
echo '<pre>Debug: tmp file:', htmlspecialchars($tempPath), "</pre>\n";
echo '<pre>Debug: target directory: ', htmlspecialchars($targetDir), "</pre>\n";
echo '<pre>Debug: real target: ', htmlspecialchars($realTargetDir), "</pre>\n";
echo '<pre>Debug: source readable: ', is_readable($tempPath), "</pre>\n";
echo '<pre>Debug: target is_dir: ', is_dir($targetDir) ? 'yes':'no', "</pre>\n";
echo '<pre>Debug: target writable: ', is_writeable($targetDir) ? 'yes':'no', "</pre>\n";
if(!move_uploaded_file( $tempPath, $uploadPath )) {
dd("File was not able to be uploaded properly.");
}
This outputs the following.
Debug: tmp file:/tmp/phpeFIjWc
Debug: target directory: /var/www/default/api/orgsync/app/storage/uploads/
Debug: real target: /var/www/default/api/orgsync/app/storage/uploads
Debug: source readable: 1
Debug: target is_dir: yes
Debug: target writable: yes
string 'File was not able to be uploaded properly.' (length=42)
To my understanding this is exactly what I want. I have a readable file and a writable directory. $_FILES['file']['error'] also spits out a 0 at me.
The files are all owned by the www-data user and group who I have checked is set at the user and group in my httpd.conf file.
User www-data
Group www-data
I am really at a loss of what step I should even take next to debug this. This is on a vagrant box if that makes any difference.
Mount Points as requested my MrTux:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
18618236 3413824 14258648 20% /
tmpfs 380120 0 380120 0% /dev/shm
/dev/sda1 495844 34543 435701 8% /boot
WCRzK17j3F03 125032444 112697476 12334968 91% /var/www
vagrant 125032444 112697476 12334968 91% /vagrant
tmp_vagrant-puppet-3_manifests
125032444 112697476 12334968 91% /tmp/vagrant-puppet-3/manifests
tmp_vagrant-puppet-3_modules-0
125032444 112697476 12334968 91% /tmp/vagrant-puppet-3/modules-0
Upvotes: 1
Views: 252
Reputation: 96363
Since is_uploaded_file
returns false, that’s where the real issue lies here – because move_uploaded_file
performs the same check, and refuses to do anything and only returns false if it has come to the conclusion that the file in question has not actually originated in an HTTP file upload received by PHP.
So go you must … and figure out why that path is not the path to an actual uploaded temp file.
Upvotes: 1
Reputation: 4771
Ok so the issue was I was working with another library and didn't realize that it was moving where the tmp file was uploaded. Although I was getting the proper location returned to me and the file existed I could no longer move it with move_uploaded_file. I which the function call to rename and everything worked great.
Upvotes: 0
Reputation: 360762
move_uploaded_files()
requires a full path + filename (or at LEAST a filename). You're providing ONLY a path.
e.g.
move_uploaded_files($source, '/upload/destination/'); //invalid
move_uploaded_files($source, '/upload/destination/foo.txt'); //VALID
you MUST provide a filename---^^^^^^^
Getting a 0
for your ['error']
means that the file was upload successfully - you're just not moving it correctly.
Upvotes: 0