1

I created an upload script using the resources from tizag, the script is returning an onscreen error however no error in the apache logs.

HTML Form

 <form action="upload.php" method="post" enctype="multipart/form-data">
 <input type="hidden" name="MAX_FILE_SIZE" value="90000000" />
  Select video to upload:
 Please choose a file: <input name="uploadedfile" type="file" /><br /> 
 <input type="submit" value="Upload File" /> 
   </form>

PHP Code

<?php
$target_path = "/var/www/html/upload/";
$target = $target_path . basename($_FILES['uploadedfile']['name'][0] );
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'] [0],        $target_path))
 { 
 echo "The file ". basename( $_FILES['uploadefile']['name'] [0]). " has been      uploaded"; 
  } 
  else {
 echo "Sorry, there was a problem uploading your file."; 
  }
  ?>

This shouldn't be very hard to impliment, but with no errors on apache it's very hard for me to troubleshoot. My php knowlegdge is limited so please bare that in mind.

Kind Regards,

Mark Couto

20
  • What is the onscreen error? Commented Mar 11, 2015 at 16:06
  • The echo return: Sorry, there was a problem uploading your file. Commented Mar 11, 2015 at 16:07
  • Add error reporting to the top of your file(s) right after your opening <?php tag error_reporting(E_ALL); ini_set('display_errors', 1); Commented Mar 11, 2015 at 16:08
  • In most cases this can mean a permissions error for the directory. Set error reporting on for detailed error in php using error_reporting(E_ALL); at the beginning of the code Commented Mar 11, 2015 at 16:09
  • 1
    I'd try and remove [0] in all of those. That's usually if you have more than one file. It's worth a shot and check for folder permissions. Commented Mar 11, 2015 at 16:09

2 Answers 2

4

This line:

$target = $target_path . basename($_FILES['uploadedfile']['name'][0] );

As it stands, $target is just a stray variable and not being used anywhere else.

It should read as:

$target_path = $target_path . basename($_FILES['uploadedfile']['name'][0] );

"I created an upload script using the resources from tizag"

The Tizag tutorial you followed doesn't change their variables.

Their example:

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

Plus, you have a typo in ['uploadefile'] which should read as ['uploadedfile']

Sign up to request clarification or add additional context in comments.

Comments

0

First ensure that php is configured to allow file upload. in your "php.ini" file search for the directive, and set it ON,

file_uploads= ON

Source : http://www.w3schools.com/php/php_file_upload.asp

3 Comments

@markjose your code is working fine for me, I think there is something wrong with the $path, can you show us your directory structure?
Fixed it ! I was using target_path instead of target and had a spelling error uploadefile not uploadedfile
Glad to hear that! you must thank fred ,He played an unique role in figuring this out..

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.