Jump to content

Recommended Posts

iv got two pages ones got a form that where a user can choose an image to upload the other page i ssupposed to store it

 

iv used variations of this code many times im trying to use it now but im stumped because it looks absoultley fine to me but its just not working

 

but the original image witch is suppsoed to be stored then resized then deleted seems to never be saved

 

http://www.thewu.site23.co.uk/createplace.php

<FORM ENCTYPE="multipart/form-data" ACTION= "storeplace.php" METHOD=POST>
 <table width="302" border="0">
  <tr>
    <td colspan="2"><H7>Name:</H7></td>
    
<td width="221" colspan="2"><input name="PName" type="text"  tabindex="1"/></td>
  </tr>
   <tr>
   <td colspan="2"><H7>Category:</H7></td>
   <td colspan="2"><select name="Category" tabindex="2">
     <option value="<?php echo ($Category) ?>"><?php echo ($Category) ?> </option>
     <option value="Pub/Club">Pub/Club</option>
     <option value="Restaurant">Restaurant</option>
     <option value="Eatery/Cafe">Eatery/Cafe</option>
     <option value="Shop">Shop</option>
     <option value="Body/Fitness">Body/Fitness</option>
     <option value="Park/Nature">Park/Nature</option>
     <option value="Other">Other</option>
   </select></td>
  </tr>
  <tr>
  <td colspan="2"><H7>Picture: </H7></td>
     <td colspan="2"><input name="image1" type="file" tabindex="2" /></td>
  </tr>
  <tr>
  <td colspan="2">
   <td colspan="2"><input name="submit" type="submit" value="Submit pics and details" tabindex="3"/></td>
  </tr>
</table>
</form>

 

on submitting the seconed page that is supposed to store the images produces many lines of error like these

 

Warning: imagecreatefromjpeg(Places/2352/image1.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/site23/public_html/thewu/storeplace.php on line 37

Warning: getimagesize(Places/2352/image1.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/site23/public_html/thewu/storeplace.php on line 40

Warning: Division by zero in /home/site23/public_html/thewu/storeplace.php on line 54

 

heres the code for that page

 

<?php 
$count = $_COOKIE['members'];
    $user = $_COOKIE['username'];
$text = ("You are logged in as $user, you are 1 of $count members ")  ; 
  
$conn = @mysql_connect( "********", "******", "*****")
or die ("could not connect to mysql");  #Connect to mysql
$rs = @mysql_select_db( "site23_thewu", $conn )
or die ("Could not select database"); #select database 

$sql = "INSERT INTO places_basics(`name`,`category`,`pic`)VALUES (\"$PName\",\"$Category\",'image')";

    $run= @mysql_query($sql, $conn )
or die(" Could not add");

mkdir("Places/$PName");
mkdir("Places/$PName/Standard");
mkdir("Places/$PName/Small");
mkdir("Places/$PName/Tiny");

if ($Image1_size >250000){$msg=$msg."Your uploaded file size is more than 250KB so please reduce the file size and then upload.<BR>";
$file_upload="false";}


if (!($Image1_type =="image/pjpeg" OR $Image1_type=="image/gif")){$msg=$msg."Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";
$file_upload="false";}

$add="Places/$PName/image1.jpg"; // the path with the file name where the file will be stored, upload is the directory name. 

if(move_uploaded_file ($Image1, $add)){
// do your coding here to give a thanks message or any other thing.
}else{echo " ";}
// make tmep file
$uploadedfile = "Places/$PName/image1.jpg";


$src = imagecreatefromjpeg($uploadedfile);

// get size of image
list($width,$height)=getimagesize($uploadedfile);


// set resize er size
if ($width > $height)
{
$target_width=550;
$ratio = $target_width/$width;
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
}
else
{
$target_height = 450;
$ratio =  $target_height/$height;
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
}
$tmp=imagecreatetruecolor($newwidth,$newheight);

// resize 
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// save resized
$filename = "Places/$PName/Standard/image1.jpg"; $_FILES['image1']['name'];
imagejpeg($tmp,$filename,100); 

////////////////////////////////////Make small version of image for profile
// make tmep file
$uploadedfile = "Places/$PName/image1.jpg";


$src = imagecreatefromjpeg($uploadedfile);

// get size of image
list($width,$height)=getimagesize($uploadedfile);


// set resize er size
if ($width > $height)
{
$target_width=250;
$ratio = $target_width/$width;
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
}
else
{
$target_height = 250;
$ratio =  $target_height/$height;
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
}
$tmp=imagecreatetruecolor($newwidth,$newheight);

// resize 
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// save resized
$filename = "Places/$PName/Small/image1.jpg"; $_FILES['image1']['name'];
imagejpeg($tmp,$filename,100); 

imagedestroy($src);
imagedestroy($tmp); 



////////////////////////////////////Make tiny version of image for searces
$uploadedfile = "Places/$PName/image1.jpg";


$src = imagecreatefromjpeg($uploadedfile);

// get size of image
list($width,$height)=getimagesize($uploadedfile);


// set resize er size
if ($width > $height)
{
$target_width=110;
$ratio = $target_width/$width;
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
}
else
{
$target_height = 110;
$ratio =  $target_height/$height;
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
}
$tmp=imagecreatetruecolor($newwidth,$newheight);

// resize 
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// save resized
$filename = "Places/$PName/Tiny/image1.jpg"; $_FILES['image1']['name'];
imagejpeg($tmp,$filename,100); 

imagedestroy($src);
imagedestroy($tmp); 
$delete = unlink("Places/$PName/image1.jpg");
header("Location: ./createplace2.php");


?>

 

it creates thje folder on the server for exmaple /Places/2352/Standard          but no image i cant see why so any help or advie would be greatly appreciated

 

Link to comment
https://forums.phpfreaks.com/topic/68091-image-storage/
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.