Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7947003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:18:29+00:00 2026-06-04T01:18:29+00:00

I have an uploading system on my website which detects whether an image is

  • 0

I have an uploading system on my website which detects whether an image is larger than a certain size and if so resizes it to be that size, using the code below:

<?php
if($count >= "1"){
    echo "<h3>The Name : ".$_POST['textfield']. " already exists. </h3>";
    echo "<h3>Please choose a unique name for this photo</h3>";
}else{  
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg"))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";



    if (file_exists("uploads/images/photography/" . $_FILES["file"]["name"]))
      {
      echo "<h3>".$_FILES["file"]["name"] . " already exists. </h3>";
      }
    else
      {

// Temporary upload image name 
$original_image = $_FILES["file"]["tmp_name"]; 

// Get the image dimensions 
$size=getimagesize( $original_image ); 

if((($size[0])<1600) || (($size[1])<1600)){

$new_image = $_FILES["file"]["name"]; 

move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/images/photography/" . $_FILES["file"]["name"]);


echo "File uploaded<br><br>"; 

echo "<img src=\"watermark.php?path=".$new_image."\" width=\"900\"><br><br>"; 

}else{

// Name to save the image as - in this case the same as the original 
$new_image = $_FILES["file"]["name"]; 

// Maximum image width 
$max_width = "1600"; 

// Maximum image height 
$max_height = "1600"; 

// Resize the image and save 
exec("convert -size {$size[0]}x{$size[1]} $original_image -thumbnail $max_widthx$max_height $new_image"); 

echo "File uploaded<br><br>"; 

echo "<img src=\"watermark.php?path=".$new_image."\" width=\"900\"><br><br>"; 

$copy = copy($new_image, "uploads/images/photography/".$new_image);
$unlink = unlink($new_image);

}

      echo "Stored in: " . "uploads/images/photography/" . $_FILES["file"]["name"];

      $date = date("d/m/y");

      $query  = mysql_query ('INSERT INTO  `ap_photos_list` ( `photo_id` ,  `category_id` ,  `subcategory_id` ,  `photo_name` ,  `photo_size` ,  `upload_date` ,  `filename` ) VALUES ("",  "'.$_REQUEST['category'].'",  "'.$_REQUEST['sub_category'].'",  "'.$_POST['textfield'].'",  "'.($_FILES["file"]["size"] / 1024).'KB",  "'.$date.'",  "'. $_FILES["file"]["name"].'")');

      $sizes = mysql_query("SELECT * FROM ap_sizes ORDER BY id ASC");

      while($row = mysql_fetch_assoc($sizes)){
            $query  = mysql_query ('INSERT INTO  `ap_photos` ( `photo_id` ,  `category_id` ,  `subcategory_id` ,  `photo_name` ,  `photo_size` ,  `upload_date` ,  `filename` , `price` , `size` ) VALUES ("",  "'.$_REQUEST['category'].'",  "'.$_REQUEST['sub_category'].'",  "'.$_POST['textfield'].'",  "'.($_FILES["file"]["size"] / 1024).'KB",  "'.$date.'",  "'. $_FILES["file"]["name"].'" , "'.$row['price'].'" , \''.$row['size'].'\')');
      }
      }
    }
  }
else
  {
  echo "<h3>Invalid file</h3>";
  }
}
?>

However one the following errors or problems occur:

  • I get the following errors:

    1. Warning: copy(DSC00103.JPG) [function.copy]: failed to open stream: No such file or directory in /homepages/19/d372249701/htdocs/ap-photo/admin/new_photo.php on line 220
    2. Warning: unlink(DSC00103.JPG) [function.unlink]: No such file or directory in /homepages/19/d372249701/htdocs/ap-photo/admin/new_photo.php on line 221
  • Or it just does not transfer the image

Both of these outcomes suggest that the image that I am uploading does not exist?!?

Any suggestions for a solution would be gratefully received.

UPDATE 1

The .htaccess file I use to protect files for copyright purposes:

RewriteEngine On
RewriteCond %{REQUEST_URI} $
RewriteRule \.(gif|jpg|png|JPG)$ - [L,F]
ErrorDocument 403 /admin/uploads/error-docs/403.shtml

UPDATE 2

I have gone through the code and identified that the problem is between:

  • exec("convert -size {$size[0]}x{$size[1]} $original_image -thumbnail $max_widthx$max_height $new_image");

and

  • $copy = copy($new_image, "/homepages/19/d372249701/htdocs/ap-photo/admin/uploads/images/photography/".$new_image);
    $unlink = unlink($new_image);

I doubt it is the echos.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:18:31+00:00Added an answer on June 4, 2026 at 1:18 am

    I would try:

    1/ displaying any errors during upload with the php errors: http://php.net/manual/en/features.file-upload.errors.php

    2/ Display the variables with echo at the different stages to see what they contain.

    e.g.

    $original_image = $_FILES["file"]["tmp_name"];
    echo "original image = $original_image<br>";
    

    3/ Isolate the individual parts of the code and check each step works.

    Editted answer:

    To be honist I did not read the Imagemagick code!

    -size {$size[0]}x{$size[1]} is not required
    

    I write my code like this which makes it a bit easier to error check the Imagemagick code as you can add an echo to show the contents of $cmd

    $cmd = "$original_image -thumbnail $max_widthx$max_height ";
    exec(" convert $cmd $new_image"); 
    

    Imagemagick is not great for error checking but you can add this:

    $array=array(); 
    echo "<pre>"; 
    $cmd = "$original_image -thumbnail $max_widthx$max_height ";
    exec(" convert $cmd $new_image 2>&1", $array);  
    echo "<br>".print_r($array)."<br></pre>";
    

    $new_image just needs to be the relative path to the save location with the image name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a WCF service for uploading images , which accepts System.IO.Stream as
I have an image uploading script in which i use the following setup to
I have one link http://devappandroid.com/Android_App/test_uploada%20.html on that i am uploading A Image and as
I'm implementing a user-based image uploading tool for my website. The system should allow
I have 2 files namely: uploading.php emaillinks.php both include a file inc.php which has
I have a plugin for uploading files using jquery uploadify. After calling a method
I have a html form for uploading a file, which is as follows: $uploadhtml
i have a web application for video uploading,In that i want to show the
how can I have itunes uploading an image to the directory of my app
I have been working on a website using MVC Preview 1 since it came

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.