Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.