PHP Upload Not Working

I am trying to get a file upload system to work on my website. However for some reason it fails every time. I created a brand new account and website with 000webhost and used the exact same code and it worked. Is there anything which might be causing this error? Thanks

Can you share the code please @zwarham , so I may evaluate.

Thanks,

  • WebMaster101 :relaxed:
<?php unlink('uploads/map.txt'); ?> Select image to upload:

Download me!

<?php $dir = "uploads/"; echo "
"; // Open a directory, and read its contents if (is_dir($dir)){ if ($dh = opendir($dir)){ while (($file = readdir($dh)) !== false){ echo "filename:" . $file . "
"; } closedir($dh); } } ?> <?php $target_dir = "uploads/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } } ?>

they work on one website but not the other

What is the website address you’re trying to upload on that won’t work. So all you are trying to do is upload images, correct?

Thanks @zwarham

I am trying to upload any file for the moment then restrict it to images, .docx, .pdf later.

Website is - http://app.netii.net/form.php which redirects to /upload.php

(the reason it says image is cause it has been adapted from an image only tutorial)

Alright I have a script that I can give you if you want, where you can upload videos, pdfs, images, etc. Do you want it? Also if you do, can you do some testing with it on your website, so we can see if it is a glitch with 000webhost or it’s your script. @zwarham

Thanks,
WebMaster101 :grinning:

Sure. Except I know my one works as I have tried it on a second 000webhost site already and it works fine.

Then it may be when 000webhost was compiling your webserver, it may have glitched the PHP. Here is the tut (the tut may not have been needed, but just trying to help):

Make a uploads folder here:

Once made, proceed to make a php file (name it whatever you want):

Should look like this:

Inside the php script, copy the following into it:

<!DOCTYPE html>

<html>

<body>

<form name="video" enctype="multipart/form-data" method="post" action="">
<input name="MAX_FILE_SIZE" value="100000000000000"  type="hidden"/>
<input type="file" name="uploadfile" />
<input type="submit" name="upload" value="SUBMIT" />
</form>

</body>

<?php
if (isset($_REQUEST['upload']))
{
$name=$_FILES['uploadfile']['name'];
 $type=$_FILES['uploadfile']['type'];
//$size=$_FILES['uploadfile']['size'];
$cname=str_replace(" ","_",$name);
$tmp_name=$_FILES['uploadfile']['tmp_name'];
$target_path="uploads/";
$target_path=$target_path.basename($cname);
   if(move_uploaded_file($_FILES['uploadfile']['tmp_name'],$target_path))
  {
    echo "Your file has been successfully uploaded";
  }
}
?>

</html>

Hope I could help @zwarham :relieved:

I just put that on my website (which my script does not work on) and it also does not work.

I put it on my spare website which my script works on and it also works.

So there is something wrong with my current website

@WebMaster101

I would have to agree because the script I gave to you works on my both of my websites. Sorry pal. :disappointed:
However could you upload anything besides images with the script I gave you?
@zwarham

I didn’t actually try an image, did a text file and a spreadsheet and neither worked

On the website that was working or not working?

Website that was not working, everything works fine on the other one

Alright, well what’re you going to do now?

Been considering getting paid hosting an a different provider so this might be the prompt to do so :stuck_out_tongue:

I obviously don’t want to port my site between domains and accounts. Might download a backup and reset my current account and upload again and see if that fixes it.

(although I also can’t seem to find a backup button like there used to be)

Again sorry, but on the brightside now you can upload things besides images.

Good luck on everything else. :grinning:

  • WebMaster101

Yeah just not here haha Thanks for your help

No problem man, glad I could help. Have fun coding :grinning:

I am trying to upload any file for the moment then restrict it to images, .docx, .pdf later.

Website is - http://Findmyiphone-locator.pe.hu which redirects to /upload.php

(the reason it says image is cause it has been adapted from an image only tutorial)

Are you talking about the script I gave to zwarham? If not there is a tutorial above with pictures and the code for the script@Mar123

Hope I could help, :grinning:
WebMaster101