1

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!

4
  • try removing the / from $storeFolder and remove this dirname( FILE ) Commented May 10, 2015 at 22:03
  • 1
    Why did you add allow_url_fopen? What's your intention and did it serve your purpose else why not go without it? just asking Commented May 10, 2015 at 22:19
  • @OmniPotens The domain name I am using is hosting multiple demo websites. one of the sites is using a ThemeForest template and some of its builtin plugins requires the allow_url_fopen to be on in order to work. I will move the site to a different domain today and will see if it works. So far no luck with fixing. Commented May 11, 2015 at 20:40
  • When you've done so and tested and still have issues then you can come around and let's work to see how to fix Commented May 12, 2015 at 11:36

2 Answers 2

1

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';
}
Sign up to request clarification or add additional context in comments.

Comments

0

Pretty sure it should be:

move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/'.basename($_FILES['file']['name']));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.