0

Hi

I have had a client asking me to look at the image upload section of the site i have built for them:

Here is the upload form code:

<form enctype="multipart/form-data" action="processupload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />
<center>Choose photo to upload: <input name="uploadedfile" type="file" /><br><br>
<input type="submit" value="Go to next step >>" /><center>
</form>

Here is the processing of the upload:

<?php

session_start();

// Where the file is going to be placed
$target_path = "images/";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path.basename($_FILES['uploadedfile']['name']);
$target_path = "images/";

$target_path = $target_path.basename($_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
   $message ="The file ".basename($_FILES['uploadedfile']['name'])."has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

header("Location: addcontact.php?file=$target_path");

?>

Here is the code to update the file once uploaded:

<form enctype="multipart/form-data" action="changephotouploadprocess.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />
<center>Choose photo to upload: <input name="uploadedfile" type="file" /><br><br>
<input type="text" name="id" value="<?php echo $_SESSION['id']; ?>">
<input type="text" name="oldfilename" value="<?php echo $_SESSION['oldfilename']; ?>">



<?php
session_start();

$id = $_GET['id'];
$oldfilename = $_GET['oldfilename'];

// Where the file is going to be placed
$target_path = "images/";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path.basename($_FILES['uploadedfile']['name']);
$target_path = "images/";

$target_path = $target_path.basename($_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
   $message ="The file ".basename($_FILES['uploadedfile']['name'])."has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

header("Location: confirmupdate.php?file=$target_path");

?>

I am having the problem where some image files are not uploading or updating.

I am not sure what is going on and I am very desperate to fix the issue.

Please can someone help?

2
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by diafol
0

I am having the problem where some image files are not uploading or updating.

Can you be more specific? Certain formats, certain sizes, certain names?

0

I have a feeling it is due to the name of the file as i have managed to upload some files in different image file types such a png, jpg and gif but some with different filenames do not i am not too sure about file sizes though

0

Again, sorry Chris, but could you be more specific with the files that are causing errors, e.g. filenames, sizes. Otherwise we're just guessing (unless somebody's seen something obviously wrong in the code).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.