Reputation: 622
I have a simple PHP file upload script to upload files. It was working fine, but after a change to PHP settings, the script is not uploading files, although I dont get any error and it says it was uploaded successfully. The script seems to be doing its job, but I cant see any files in my uploads folder. Nothing is changed in script since it was working other than a change in php settings where I had to request my host to do following the following PHP settings:
max_execution_time 60
memory_limit 128M
post_max_size 32M
upload_max_filesize 32M
allow_url_fopen = On (this was the last change, which I believe is the causing the issue).
Here is my upload script:
$ds = DIRECTORY_SEPARATOR;
$storeFolder = "uploads/";
$fileupload = basename( $_FILES['file']['name']);
$fileType = $_FILES['file']['type'];
$fileSize = $_FILES['file']['size'];
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath. $fileupload;
move_uploaded_file($tempFile,$targetFile);
Note: I am not trying to upload a huge file, Like I said, the script doesn't through any error, but I cant see the files in my uploads folder.
I am not even sure if this is because of my PHP settings changes. Any help is highly appreciated!
Upvotes: 1
Views: 115
Reputation: 1325
I think you setting are right but you have error in your php code, line where you are specifing your directory to store the file. You can go with simple
$storeFolder = "uploads/";
$fileupload = basename($_FILES['file']['name']);
$fileType = $_FILES['file']['type'];
$fileSize = $_FILES['file']['size'];
$tempFile = $_FILES['file']['tmp_name'];
$targetFile = $storeFolder.$fileupload;
if(move_uploaded_file($tempFile,$targetFile)){
echo 'file uploaded' ;
else
echo 'file not uploaded';
}
Upvotes: 1
Reputation: 10617
Pretty sure it should be:
move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/'.basename($_FILES['file']['name']));
Upvotes: 0