Jump to content

Why won't the images upload with this script?


simcoweb

Recommended Posts

This code should upload a picture file to the designated folder. But.. it's not. NO pic is getting uploaded even though it provides a confirmation and no errors.

[code]<html>
<head>
<title>Test Upload Form</title>
</head>
<body>
<?php
//image upload test
$file_dir = "/home2/wwwplat/public_html/images/";
$file_url = "http://www.plateauprofessionals.com/images";

if (isset($image))
{
  print "<center>Image path: $image<br>\n";
  print "<center>Image name: $image_name<br>\n";
  print "<center>Image size: $image_size bytes<br>\n";
  print "<center>Image type: $image_type<p>\n\n";
  if ($image_type == "image/gif" )
  {
copy ($image, "$image_dir/$image_name") or die("Could not copy");
print "<img src=\"$file_url/$image_name\"><p>\n\n";
}
}
?>
<form action="<?print $PHP_SELF?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="file" accept=".jpg" size="20" name="image" title="Image Upload" /><br>
<input type="submit" value="Submit">
</form>[/code]

I've validated this code by comparing it to some code in a Learn PHP book. Anyone see why it doesn't work?
[url=http://www.phpfreaks.com/forums/index.php/topic,104755.0.html]http://www.phpfreaks.com/forums/index.php/topic,104755.0.html[/url]

try the code in this thread it works fine for me to upload pic  ;)

just change the relevant variables and your away ;D
It appears as though that code wasn't working and you were seeking help with it. Does it work?

What i'm actually trying to do is create a upload a pic, create a thumbnail that uploads at the same time, and import data into the mysql database pertaining to all the form fields and the pic references.
This works for me.
[code]<?php
//image upload test
$file_dir = "/home2/wwwplat/public_html/images/";
$file_url = "http://www.plateauprofessionals.com/images";

if (isset($_POST['submit']))
{
$image_name = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$image_type = $_FILES['image']['type'];
$uploadfile = $file_dir.basename($image_name);
if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) {
  echo "File is valid, and was successfully uploaded.\n";
} else {
  echo "Possible file upload attack!\n";
}
  print "<center>Image path: $file_dir<br>\n";
  print "<center>Image name: $image_name<br>\n";
  print "<center>Image size: $image_size bytes<br>\n";
  print "<center>Image type: $image_type<p><br>\n\n";
      print "<img src=\"$file_url/$image_name\"><p>\n\n";
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="file" accept=".jpg" size="20" name="image" title="Image Upload" /><br>
<input type="submit" name=submit value="Submit">
</form>

</body>

</html>[/code]

Ray
Thanks Ray. Actually this script was a test to see if there was a problem with uploading images to my server since i've been working on another script that for some reason just won't upload the image and create the thumbnail.

See this thread: http://www.phpfreaks.com/forums/index.php/topic,104388.45.html

I'm creating a member profile page and a member's list/summary page. The profile will contain the full image and the summary page will have a thumbnail. I'm looking for code to parse the data for the profile entry form which also has a file upload field. The goal is to upload the original image and also create a thumbnail at the same time. The reference for each is entered into the mysql database so I can then summon them up in the profile display pages.

Any ideas?

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.