jaxdevil Posted October 13, 2008 Share Posted October 13, 2008 I have my image upload script inside an if statement, that checks if there is a file selected or not, if not it says "no file selected", but if there is a file then it runs the script. It will not do anything but show "no file selected" even though I am using a display to display the posts and the file is there in the array but it is not working in the script. Anyone see what is wrong? <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?> <? $ip_address = getenv(REMOTE_ADDR); $last_edit = date("m|d|Y"); ?> <? $filesize=$HTTP_POST_FILES['ufile']['size'][0]; if ( $filesize == '' ) { ?> No file selected <? } else { ?> <? echo "filename: ".$HTTP_POST_FILES['ufile']['name'][0]; ?> <? $path1= $_SERVER['DOCUMENT_ROOT']."/images/logo/temp/2/".$HTTP_POST_FILES['ufile']['name'][0]; copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1); $orig_filename = $path1; $new_filename = $_SERVER['DOCUMENT_ROOT']."/images/logo/temp/logo.jpg"; $status = rename($orig_filename, $new_filename) or exit("Could not add the image_file"); echo "Full size image added successfully!<br><br>"; function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) { // open the directory $dir = opendir( $pathToImages ); // loop through it, looking for any/all JPG files: while (false !== ($fname = readdir( $dir ))) { // parse path for the extension $info = pathinfo($pathToImages . $fname); // continue only if this is a JPEG image if ( strtolower($info['extension']) == 'jpg' ) { // load image and get image size $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" ); $width = imagesx( $img ); $height = imagesy( $img ); // calculate thumbnail size $new_width = $thumbWidth; $new_height = floor( $height * ( $thumbWidth / $width ) ); // create a new temporary image $tmp_img = imagecreatetruecolor( $new_width, $new_height ); // copy and resize old image into new image imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); // save thumbnail into a file imagejpeg( $tmp_img,"{$pathToThumbs}{$fname}") or die ("Could not create thumbnail image from JPEG"); } } // close the directory closedir( $dir ); } // call createThumb function and pass to it as parameters the path // to the directory that contains images, the path to the directory // in which thumbnails will be placed and the thumbnail's width. // We are assuming that the path will be a relative path working // both in the filesystem, and through the web for links createThumbs($_SERVER['DOCUMENT_ROOT']."/images/logo/temp/",$_SERVER['DOCUMENT_ROOT']."/images/logo/","160"); chmod("http://".$_SERVER['HTTP_HOST']."/images/logo/logo.jpg", 0755); echo "Thumbnail image added successfully!"; ?> <? } ?> <? $query="UPDATE company SET `c_name`='$c_name',`c_address` = '$c_address',`c_city` = '$c_city',`c_state` = '$c_state',`c_zip` = '$c_zip',`c_telephone` = '$c_telephone',`c_fax` = '$c_fax',`c_website` = '$c_website',`ip_address` = '$ip_address', `last_edit` = '$last_edit',`edit_record`='$_COOKIE[name]'"; $result =mysql_query($query) or die ("Problem with the query $query<br>: " . mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/128237-solved-image-upload-not-working/ Share on other sites More sharing options...
BlueSkyIS Posted October 13, 2008 Share Posted October 13, 2008 could be your use of a scalar as an array. i would try removing the index [0] from the end of your $HTTP_POST_FILES['ufile'] values, e.g., $HTTP_POST_FILES['ufile']['name'] NOT $HTTP_POST_FILES['ufile']['name'][0] Link to comment https://forums.phpfreaks.com/topic/128237-solved-image-upload-not-working/#findComment-664177 Share on other sites More sharing options...
jaxdevil Posted October 13, 2008 Author Share Posted October 13, 2008 I tried with and without, neither works, but it needs to be with as I have the [] array setup on the file. I have tried removing it from the file name and the image upload script, and adding it, and neither works. What I end up with is it making a folder called logo.jpg . I have tried with $_FILES and $HTTP_POST_FILES Link to comment https://forums.phpfreaks.com/topic/128237-solved-image-upload-not-working/#findComment-664200 Share on other sites More sharing options...
jaxdevil Posted October 13, 2008 Author Share Posted October 13, 2008 I figured it out, I went all around the world trying all different things to fix it, and the problem was on the form, I did not have enctype="multipart/form-data" in the form. Doh! Link to comment https://forums.phpfreaks.com/topic/128237-solved-image-upload-not-working/#findComment-664263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.