Jump to content

deal with uploaded files


ohdang888

Recommended Posts

here's my code:

 

i'm not getting any PHP errors

 

 

I don't think the file is even getting uploaded. Because when i print_r($_FILES) i'm just getting "array( )", so its empty

 

any ideas?Thanks

<br><form id="Upload" action="chapter.php?id=<?php echo $id ?>&action=pic" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="3000" />
<input id="file" type="file" name="file">
<input type="submit" name="pic_submit" value="Upload"></form><br>
<?php
}

if($_GET['action'] == "pic"){
print_r($_FILES);

$name = $_FILES["file"]["name"];
$type = $_FILES["file"]["type"];
$size = ($_FILES["file"]["size"] / 1024);
$uploaded_file= basename($_FILES["file"]["tmp_name"]);

echo $type;
echo "name: $name";

if($type == ".gif" or $type == ".jpg" or $type == ".png" or $type == ".jpeg"){
//do nothing
}else{
echo "Invalid file type -- you tried to upload a $type file<br>";
$stop = "yes";
}
if($size >= 1500){
echo "File must be less than 1.5 megabytes<br>";
$stop = "yes";
}
if ($_FILES["file"]["error"] > 0){
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
$stop = "yes";
}

if($stop != "yes"){
$new_name = "chap_pics/".$chapter_id.$type;
if(move_uploaded_file($uploaded_file, $new_name)){
echo "<b><br>File uploaded!</b><br>";
echo $new_name;
}else{
echo "<br>File upload failed.<br>";
}

}else{
echo "File upload stopped.<br>";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/117641-deal-with-uploaded-files/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.