justAnoob Posted March 23, 2009 Share Posted March 23, 2009 I'm looking to rename the image before it is uploaded to the server. Can someone point me in the right direction. The user has a textbox on the page so they can type in the name of the image they are uploading. I want them to be able to give it a name insted of using the actual filename. Here is what we got so far for the upload. <?php $itemname = mysql_real_escape_string($_POST['itemname']); $description = mysql_real_escape_string($_POST['description']); define ("MAX_SIZE","1000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if(isset($_POST['Submit'])) { $image=$_FILES['image']['name']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "gif") && ($extension != "png")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } $image_name=time().'.'.$extension; $newname="userimages/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); ?php Link to comment https://forums.phpfreaks.com/topic/150778-solved-renaming-image-before-upload/ Share on other sites More sharing options...
FaT3oYCG Posted March 23, 2009 Share Posted March 23, 2009 here is an extremley simple upload script php thingyma bob that i have for testing something out it has what you need <?php $result = 0; // Edit upload location here $destination_path = getcwd().DIRECTORY_SEPARATOR; $target_path = $destination_path . basename( $_FILES['myfile']['name']); if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) { $result = 1; } ?> Link to comment https://forums.phpfreaks.com/topic/150778-solved-renaming-image-before-upload/#findComment-792170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.